﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZhiAo.Management;
using ZhiAo.CommonLibrary;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDefalut();
        }
    }

    private void LoadDefalut()
    {
        if (CookieHelper.GetCookie("chkRemPwd") == "true")
        {
            this.txtUserName.Text = CookieHelper.GetCookie("userName");
            this.txtPassword.Text = CookieHelper.GetCookie("password");
            this.chkRemPwd.Checked = true;
        }
        if (CookieHelper.GetCookie("chkAutoLogin") == "true")
        {
            if (ZhiAo.Management.UserInfo.Login(CookieHelper.GetCookie("userName"), CookieHelper.GetCookie("password")))
            {
                Response.Redirect("Base_Data/Base_Data/Index.aspx");                
            }
            else
            {
                Response.Cookies.Clear();
                Request.Cookies.Clear();
            }
        }
    }


    protected void btnLogin_Click(object sender, EventArgs e)
    {

        try
        {
            if (Session["CheckCode"].ToString() != txtChkCode.Text)
            {
                this.txtChkCode.Text = "";
                Response.Write("<script>alert('验证码错误')</script>");
                return;
            }
            if (ZhiAo.Management.UserInfo.Login(this.txtUserName.Text, this.txtPassword.Text))
            {
                if (this.chkRemPwd.Checked)
                {
                    CookieHelper.SetCookie("chkRemPwd", "true");
                }
                if (this.chkAutoLogin.Checked)
                {
                    CookieHelper.SetCookie("chkAutoLogin", "true");
                }
                Response.Redirect("Base_Data/Base_Data/Index.aspx");
                //Response.Write("<script>location.href='Base_Data/Base_Data/Index.aspx'</script>");
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('用户名或者密码错误')</script>");
        }

    }
}
